package com.jic.manager.controller.rest.conf;

import com.jic.common.base.vo.RestResult;
import com.jic.conf.request.SysCarouselFigureRequest;
import com.jic.conf.response.SysCarouselFigureResponse;
import com.jic.manager.common.util.BeanUtil;
import com.jic.manager.entity.SysCarouselFigure;
import com.jic.manager.service.SysCarouselFigureService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: wwb
 * @date: 2020-01-09
 * @remark: BBC接口 CMS
 */
@Api(tags = "H5-轮播图管理")
@RestController
@RequestMapping("/apiSysCarouselFigure")
@Slf4j
public class ApiSysCarouselFigure{

    @Resource
    private SysCarouselFigureService sysCarouselFigureService;

    /**
     * 分页查询
     * @param sysCarouselFigureRequest
     * @return
     */
   @PostMapping(value = "/listSysCarouselFigure")
    public RestResult<List<SysCarouselFigureResponse>> listSysCarouselFigure(@RequestBody SysCarouselFigureRequest sysCarouselFigureRequest) {
       try {
           List<SysCarouselFigure> carouselFigureList = sysCarouselFigureService.query(sysCarouselFigureRequest);
           List<SysCarouselFigureResponse> sysCarouselFigureResponseList=new ArrayList<>();
           carouselFigureList.forEach(item->{
               SysCarouselFigureResponse sysCarouselFigureResponse=new SysCarouselFigureResponse();
               BeanUtil.copy(item,sysCarouselFigureResponse);
               sysCarouselFigureResponseList.add(sysCarouselFigureResponse);
           });
           return  RestResult.success(sysCarouselFigureResponseList);
       } catch (Exception e) {
           log.error("查询轮播图失败========》",e.getMessage());
           return RestResult.error("9999",e.getMessage());
       }
   }


}
